<template>
  <div class="dashboard">
    <h2 class="page-title">📊 数据概览</h2>
    
    <el-row :gutter="20" class="stats-row">
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-content">
            <el-icon class="stat-icon" color="#409EFF"><User /></el-icon>
            <div>
              <div class="stat-value">{{ stats.users }}</div>
              <div class="stat-label">用户总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-content">
            <el-icon class="stat-icon" color="#67C23A"><OfficeBuilding /></el-icon>
            <div>
              <div class="stat-value">{{ stats.enterprises }}</div>
              <div class="stat-label">企业总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-content">
            <el-icon class="stat-icon" color="#E6A23C"><Briefcase /></el-icon>
            <div>
              <div class="stat-value">{{ stats.jobs }}</div>
              <div class="stat-label">岗位总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-content">
            <el-icon class="stat-icon" color="#F56C6C"><Document /></el-icon>
            <div>
              <div class="stat-value">{{ stats.applications }}</div>
              <div class="stat-label">投递记录</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-card class="recent-card" shadow="never">
      <template #header>
        <div class="card-header">
          <span>系统概况</span>
        </div>
      </template>
      <el-descriptions :column="2" border>
        <el-descriptions-item label="简历总数">{{ stats.resumes }}</el-descriptions-item>
        <el-descriptions-item label="面试经验">{{ stats.experiences }}</el-descriptions-item>
        <el-descriptions-item label="面试题目">{{ stats.questions }}</el-descriptions-item>
        <el-descriptions-item label="面试日程">{{ stats.schedules }}</el-descriptions-item>
      </el-descriptions>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { User, OfficeBuilding, Briefcase, Document } from '@element-plus/icons-vue'

const stats = ref({
  users: 0,
  enterprises: 0,
  jobs: 0,
  applications: 0,
  resumes: 0,
  experiences: 0,
  questions: 0,
  schedules: 0
})

// 加载统计数据
const loadStats = async () => {
  try {
    const res = await fetch('http://localhost:7001/api/statistics/overview')
    if (res.ok) {
      const json = await res.json()
      if (json.code === 200 && json.data) {
        stats.value = json.data
      }
    }
  } catch (e) {
    console.error('获取统计数据失败:', e)
    // 使用模拟数据
    stats.value = {
      users: 128,
      enterprises: 45,
      jobs: 234,
      applications: 567,
      resumes: 320,
      experiences: 89,
      questions: 156,
      schedules: 234
    }
  }
}

onMounted(() => {
  loadStats()
})
</script>

<style scoped>
.dashboard {
  padding: 20px;
}

.page-title {
  margin: 0 0 30px 0;
  font-size: 24px;
  color: #333;
}

.stats-row {
  margin-bottom: 30px;
}

.stat-card {
  border-radius: 8px;
  transition: transform 0.3s;
}

.stat-card:hover {
  transform: translateY(-5px);
}

.stat-content {
  display: flex;
  align-items: center;
  gap: 15px;
}

.stat-icon {
  font-size: 48px;
}

.stat-value {
  font-size: 32px;
  font-weight: bold;
  color: #333;
}

.stat-label {
  font-size: 14px;
  color: #666;
  margin-top: 5px;
}

.recent-card {
  border-radius: 8px;
}

.card-header {
  font-weight: 600;
  font-size: 16px;
}
</style>

